<template>
	<!-- 保养模板筛选框 -->
	<view class="taskFilter">
		<view class="title">{{ title }}</view>
		<view class="filterContent">
			<view class="main">
				<view class="left">
					<view class="leftContent">
						<view :class="['leftItem', actIdx == index ? 'act' : '']" @click="handleClickLeft(index, item)" v-for="(item, index) in list" :key="index">
							{{ item.name }}
							<view class="redDot" v-if="isShowRedDot(item.id)"></view>
							
						</view>
					</view>
				</view>

				<view class="right">
					<view class="rightContent">
						<view :class="['tagItem', isSelect(e.id) ? 'activeTage' : '']" v-for="(e, i) in childList" :key="e.id" @click="chooseTag(e)">{{ e.name }}</view>
					</view>
					<!-- 	 <view v-else class="empty">
						 暂无数据
					 </view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { elevatorType, contentTemp } from '@/apis/maintains.js';
export default {
	props: {
		title: {
			type: String,
			default: '保养任务'
		}
	},
	data() {
		return {
			actIdx: '',
			list: [], // 父数组
			childList: [], // 子数组
			selectArr: []
		};
	},
	created() {
		this.fetchChildList();
	},
	methods: {
		
		// 重置组件
		initData(arr) {
			this.selectArr = arr;
		},
		isSelect(id) {
			return this.selectArr.find(e => e.id == id);
		},
		handleClickLeft(i, res) {
			this.actIdx = i;
			this.fetchChildList();
		},
		fetchChildList() {
			contentTemp().then(res => {
				if (res) {
					this.list = res.data;
					this.childList = this.list[this.actIdx ? this.actIdx : 0].children;
				}
			});
		},
		// 判断红点是否显示
		 isShowRedDot(id) {
		   // console.log(this.selectArr.find((e)=>id==e.parentId),2222)
			return this.selectArr.find((e)=> {
				return id == e.parentId;
			});
		 },
		// 选择某个标签
		chooseTag(res) {
			let idx = this.selectArr.findIndex(item => item.id == res.id);
			if (idx !== -1) {
				this.selectArr.splice(idx, 1);
			} else {
				this.selectArr.push({ id: res.id, parentId: res.parentId });
			}
			this.$emit('chooseTemp',this.selectArr);
		}
	}
};
</script>

<style lang="scss" scoped>
.taskFilter {

	.title{
		color: #333;
		padding: 0 30rpx;
		font-weight: 600;
		font-size: 30rpx;
	}
	// display: flex;
	.filterContent {
		height: 300rpx;
		overflow-y: auto;
		
	}
	.main {
		display: flex;
	}
	.left {
		background: #f6f6f6;
		height: 300rpx;
		overflow: auto;
		.leftItem {
			width: 232rpx;
			// height: 80rpx;
			padding: 20rpx 46rpx;
			display: flex;
			box-sizing: border-box;
			justify-content: center;
			align-items: center;
			background: #f6f6f6;
			font-size: 28rpx;
			color: #666;
			position: relative;
		}
		.redDot {
			width: 10rpx;
			height: 10rpx;
			border-radius: 50%;
			background-color: #e02020;
			position: absolute;
			right: 16rpx;
			top: 0;
		}
		.act {
			color: #0091ff;
			background-color: #fff;
		}
	}

	.right {
		background-color: #fff;
		width: calc(100% - 232rpx);
		padding-left: 30rpx;
		height: 300rpx;
		overflow: auto;
		.rightContent {
			display: flex;
			width: 100%;
			flex-wrap: wrap;
		}
		.tagItem {
			width: 216rpx;
			height: 48rpx;
			border: 2rpx solid #cccccc;
			border-radius: 8rpx;
			text-align: center;
			line-height: 48rpx;
			margin-bottom: 20rpx;
			color: #666;
			font-size: 28rpx;
			// padding: 0 16rpx;
			margin-right: 16rpx;
			overflow: hidden; /*文本超出隐藏*/
			text-overflow: ellipsis; /*文本超出显示省略号*/
			white-space: nowrap;
		}
		.tagItem:nth-child(odd) {
			margin-right: 20rpx;
		}
		.activeTage {
			border-color: #0091ff;
			color: #0091ff;
		}
	}
	.empty {
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
</style>
